<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
    <style type="text/css">
        body, html {
            width: 100%;
            height: 100%;
            margin: 0;
            font-family: "微软雅黑";
        }

        #allmap {
            height: 700px;
            width: 100%;
        }

        #r-result {
            width: 100%;
            font-size: 14px;
        }
    </style>
    <script type="text/javascript"
            src="http://api.map.baidu.com/api?v=2.0&ak=你的秘钥"></script>
    <title>百度定位信息</title>
</head>
<body>
<div id="allmap"></div>
<div id="r-result">

    <input type="button" value="获取我的位置" onclick="get_location()"/>
</div>
</body>
</html>
<script type="text/javascript">
    // 百度地图API功能

    var map = new BMap.Map("allmap");
    map.centerAndZoom(new BMap.Point(118.3088230000, 32.3002390000), 18);
    map.enableScrollWheelZoom(true);
    var navigationControl = new BMap.NavigationControl({
        // 靠左上角位置
        anchor: BMAP_ANCHOR_TOP_LEFT,
        // LARGE类型
        type: BMAP_NAVIGATION_CONTROL_LARGE,
        // 启用显示定位
        enableGeolocation: true
    });
    map.addControl(navigationControl);

    function get_location() {

        var address_latitude = {
        {
            address_latitude | safe
        }
    }
        ;
        var address_longitude = {
        {
            address_longitude | safe
        }
    }
        ;
        var address_data = {
        {
            address_data | safe
        }
    }
        ;


        var point = []; //存放标注点经纬信息的数组
        var marker = []; //存放标注点对象的数组
        for (var i = 0; i < address_longitude.length; i++) {
            point[i] = new BMap.Point(address_longitude[i], address_latitude[i]); //循环生成新的地图点
            marker[i] = new BMap.Marker(point[i]); //按照地图点坐标生成标记
            map.addOverlay(marker[i]);
        }

        for (i = 0; i < marker.length; i++) {
            (function () {
                var index = i;
                marker[index].addEventListener('click', function () {
                    this.openInfoWindow(new BMap.InfoWindow(address_data[index]));
                });
            })();
        }
    }

</script>
